﻿using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Filters;
using Microsoft.VisualBasic;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace Y2.Filters
{
    public class LoginFilterAttribute : ActionFilterAttribute
    {
        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            var userid = filterContext.HttpContext.Session.GetString("id");

            // 检查登陆信息
            if (userid == null)
            {
                // 用户未登陆 - 跳转到登陆界面
                filterContext.Result = new RedirectResult("/users/users");
            }
            base.OnActionExecuting(filterContext);
        }
    }
}
